package com.example.love_margin.Mapper;



import com.example.love_margin.Entity.Search;
import com.example.love_margin.Mapper.configuer.DeleteMany;
import com.example.love_margin.Mapper.configuer.SearchPets;

import com.example.love_margin.Mapper.configuer.SeletPetPicture;
import com.example.love_margin.Mapper.configuer.upOneSearch;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SearchMapper {

    //增加（寻宠/寻主），返回id值
    @Insert("INSERT INTO search(search_pet_class,search_pet_category,search_pet_name,search_pet_sex,search_pet_area,search_pet_varieties,search_pet_age,search_pet_message,search_pet_state,search_pet_contact,user_id,search_pet_picture)" +
            "values(#{search_pet_class},#{search_pet_category},#{search_pet_name},#{search_pet_sex},#{search_pet_area},#{search_pet_varieties},#{search_pet_age},#{search_pet_message},#{search_pet_state},#{search_pet_contact},#{user_id},#{search_pet_picture})")
    int addSearch(Search search);


//    //增加关系表
//    @Insert("INSERT INTO user(search_id,user_id)values(#{search_id},#{user_id})")
//    int addSearchRelationship(@Param("search_id") int search_id,@Param("user_id") int user_id);

    //删除（寻宠/寻主）
    @Delete("DELETE FROM search WHERE search_id=#{search_id}")
    int deleteSearch(@Param("search_id") int search_id);

    //删除某用户的所有（寻宠/寻主）
    @Delete("DELETE FROM search WHERE user_id=#{user_id}")
    int deleteUserSearch(@Param("user_id") int user_id);

    //查询多个对象的图片的地址用以删除
    @SelectProvider(type = SeletPetPicture.class,method = "SelectPetP")
    List<String> selectPetAll(String URL);

    //批量删除

    @DeleteProvider(type = DeleteMany.class,method = "deleteM")
    int deleteScienceM(String lk);


    //通过id进行修改宠物信息
    @UpdateProvider(type = upOneSearch.class, method = "UpOnePet")
    int upOneSearchPet(Search search);

    //通过id修改找到状态
    @Update("UPDATE search SET search_pet_state=#{search_pet_state} WHERE search_id = #{search_id}")
    int passSearch(@Param("search_pet_state") String search_pet_state,@Param("search_id") int search_id);


    @Select("SELECT * FROM search WHERE search_id = #{search_id}")
    Search selectOneSearch(@Param("search_id") int search_id);

    @Select("SELECT * FROM search WHERE search_pet_class = #{search_pet_class} AND user_id = #{user_id}")
    List<Search> selectMySearch(@Param("search_pet_class") String search_pet_class,@Param("user_id") int user_id);

    @Select("SELECT search_id FROM search WHERE user_id = #{user_id}")
    List<String> selectMySearchPet(@Param("user_id") int user_id);

//    @Select("SELECT * FROM search")
//    List<Search> selectSearch();

    //多条件加关键词加分页
    @SelectProvider(type = SearchPets.class,method = "selectMany")
    List<Search> selectSearchMany(String pet_category, String pet_varieties, String pet_sex, String key);

}
